package daobeauty.interceptor.returntype.executor.sqlquery;

import org.hibernate.SQLQuery;

import daobeauty.dao.Limiting;
import daobeauty.interceptor.returntype.handler.ReturnTypeHandler;

public class ListSqlQueryExecutionStrategy implements SqlQueryExecutionStrategy {
	public static final ListSqlQueryExecutionStrategy INSTANCE = new ListSqlQueryExecutionStrategy();
	
	public Object execute(ReturnTypeHandler returnTypeHandler, SQLQuery query, Limiting limiting) {
		if (limiting!=null){
			query.setMaxResults(limiting.getMaxResults());
			query.setFirstResult(limiting.getOffset());
		}
		return returnTypeHandler.convert(query.list());
	}
}
